<% layout('/layouts/default.html', {title: '收支明细单查询', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('收支明细单详情')}
                <% if (hasPermi('financial:incomeExpenditure:edit')
                    && !(incomeExpenditure.accountingReceivable != "" || incomeExpenditure.accountingPayable != "") ){ %>
                    <button type="button" class="btn btn-primary" id="editView">${text('编辑单据')}</button>
                <% } %>
                <% if ((incomeExpenditure.accountingReceivable == null || incomeExpenditure.accountingReceivable == ""
                        || incomeExpenditure.accountingPayable == null || incomeExpenditure.accountingPayable == "")&&(incomeExpenditure.userFlag == '1' || hasPermi('financial:incomeExpenditure:ysyf'))){ %>
                    <button type="button" class="btn btn-primary" id="createYsYf"> ${text('生成应收应付')}</button>
                <% } %>
            </div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${incomeExpenditure}" action="${ctx}/financial/incomeExpenditure/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="incomeExpenditureId" id="incomeExpenditureId" />
				<div class="row">
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="incomeExpenditureCode" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="serviceOrderId" items="${listServiceOrder}"
                                itemLabel="serviceOrderCode" itemValue="serviceOrderId" blankOption="true" class="form-control " disabled="true"/>
                            </div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="customerId" items="${listCustomer}"
                                itemLabel="customerName" itemValue="customerId" blankOption="true" class="form-control required" disabled="true" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('供应商名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="supplierId" items="${listSupplier}"
                                itemLabel="supplierName" itemValue="supplierId" blankOption="true"  class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外币币种')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="currency" dictType="sys_bizhong" blankOption="true" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外商名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="supplierId" items="${listSupplier}"
                                itemLabel="supplierName" itemValue="supplierId" blankOption="true" class="form-control " disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('应收单编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="accountingReceivable" items="${listAccountRec}"
                                itemLabel="arCode" itemValue="arId" blankOption="true" class="form-control " disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('应付单编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="accountingPayable" items="${listAccountPay}"
                                itemLabel="apCode" itemValue="apId" blankOption="true" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required">*</span> ${text('录入类型')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="scannerType" id="scannerType" dictType="erp_scanner_type" blankOption="true" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('费用项目')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:select path="expenseItem" items="${listExpenseItem}"
                                itemLabel="fixedExpenseName" itemValue="fixedExpenseId" blankOption="true" disabled="true" class="form-control"/>
                            </div>
                        </div>
                    </div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('车辆明细')} </div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('收入金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="incomeAmount" class="form-control number" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('支出金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="expenditureAmount" class="form-control number" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="ml10 mr10">
                    <table id="incomeExpenditureDetailDataGrid"></table>
                </div>
                <div class="form-unit">${text('附件信息')}</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${incomeExpenditure.id}" bizType="incomeExpenditure_file"
									uploadType="all" class="" readonly="true" preview="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('系统信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createDate" class="form-control" disabled="true"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createBy" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化收支车辆明细DataGrid对象
$("#incomeExpenditureDetailDataGrid").dataGrid({
	data: ${toJson(incomeExpenditure.incomeExpenditureDetailList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'incomeExpenditureDetailId', editable:true, hidden:true},
		{header:'${text("车辆")}', name:'tcar.carName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("车型")}', name:'model', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("车架号")}', name:'frameNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("外币价格")}', name:'foreignCurrencyPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("收入金额")}', name:'incomeAmount', width:150, editable:true },
		{header:'${text("支出金额")}', name:'expenditureAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("收支明细单ID")}', name:'incomeExpenditureId.incomeExpenditureId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],

	// 编辑表格参数
	editGrid: false,				// 是否是编辑表格
	editGridInitRowNum:0,		// 编辑表格的初始化新增行数
    showFooter:true,
	editGridAddRowBtn: $('#incomeExpenditureDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {incomeExpenditureDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'incomeExpenditureDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,incomeExpenditureDetailId,carId,model,frameNumber,foreignCurrencyPrice,incomeAmount,expenditureAmount,incomeExpenditureId.incomeExpenditureId,', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){
// 设置底部合计行数据(设置合计行)
        $('#incomeExpenditureDetailDataGrid').dataGrid("footerData", "set", {
            'tcar.carName' : '合计：',
            'incomeAmount': "${totalIncomeAmount}",
            'expenditureAmount': "${totalExpenditureAmount}"
        }, false);
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>

<script>
    $("#editView").click(function () {
        var id = $("#incomeExpenditureId").val();
        var URL = '${ctx}/financial/incomeExpenditure/form?incomeExpenditureId=' + id;
        window.location.href =URL;
    });

    $("#createYsYf").click(function(){
        $.ajax({
            type: "POST",
            async : false,
            url: "${ctx}/financial/incomeExpenditure/createYsYf",
            data: {"incomeExpenditureId": $("#incomeExpenditureId").val()},
            success: function (data) {
                js.showMessage(data.message);
                location.reload();
            }
        });
    });


</script>


